var fn=function(){
    console.log("执行fn");
    return "this is a fn"; 
};
var fn1=function(){
    var a="this is a fn1";
}
var p={
    then:function(resolve,reject){
        reject("error:this is like a promise");
        resolve("success:this is like a promise");
    }
}
console.log("-------------promise.resolve-------------------")
Promise.resolve(fn()).then(
    function(value){
        console.log(value);
    }
)
console.log("执行promise.resolve后")
Promise.resolve(fn1()).then(
    function(value){
        console.log(value);
    }
)

//https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve
//promise.resolve只能接收三种值：
//传递一个promise则会得到这个promise
//传递一个非promise非thenable的立即值，会转换成promise
Promise.resolve(34).then(
    function(value){
        console.log(value);
    }
)

//传递一个非promise的thenable，会试图展开thenable
Promise.resolve(p).then(
    //只有第一次决议会生效，一旦生效就不能修改了，这样就保证了它的可靠性
    function(value){
        console.log(value);
    },
    function(value){
        console.log(value);
    }
)